home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC24Teach / Teach.c / UMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  7.9 KB  |  299 lines  |  [TEXT/pdos]

  1. /*********************************************************************
  2. *
  3. * teach umenu.c -- Version 3.0 
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements 
  12. * menus in the Teach program.
  13. *
  14. *********************************************************************/
  15.  
  16. #include <types.h>
  17. #include <control.h>
  18. #include <desk.h>
  19. #include <font.h>
  20. #include <intmath.h>
  21. #include <memory.h>
  22. #include <menu.h>
  23. #include <textedit.h>
  24. #include <window.h>
  25. #include "teach.h"
  26.  
  27. extern unsigned int     quitFlag, userID;
  28. extern WmTaskRec        event;
  29.  
  30.  
  31.  
  32. /*********************************************************************
  33. * doQuitItem
  34. *
  35. * Just set the quitFlag -- that will do it.
  36. *
  37. *********************************************************************/
  38. void    doQuitItem()
  39. {
  40.     quitFlag++;
  41. }
  42.  
  43.  
  44.  
  45. /*********************************************************************
  46. * doAboutItem
  47. *
  48. * Display the vanity box.
  49. *
  50. *********************************************************************/
  51. void    doAboutItem()
  52. {
  53.     AlertWindow(refIsResource * 2, NULL, 1L);
  54. }
  55.  
  56.  
  57.  
  58. /*********************************************************************
  59. * doSelectAll
  60. *
  61. * Tell TextEdit to select all the text for the front window.
  62. *
  63. *********************************************************************/
  64. void    doSelectAll()
  65. {
  66.     CtlRecHndl  thisHndl;
  67.  
  68.     thisHndl = GetCtlHandleFromID(FrontWindow(), MainWindowID);
  69.     TESetSelection(0L, 0xFFFFFFFFL, thisHndl);
  70. }
  71.  
  72.  
  73.  
  74. /*********************************************************************
  75. * doChooseFont
  76. *
  77. * Use ChooseFont to select a different font, and then have TextEdit
  78. * change the selected text in the top window.
  79. *
  80. *********************************************************************/
  81. void    doChooseFont()
  82. {
  83.     Handle      tempHndl;
  84.     CtlRecHndl  thisHndl;
  85.     TEStyle     thisStyle;
  86.  
  87.     tempHndl = (Handle)NewHandle(20L, userID, 0, NULL);
  88.         /* Create a Temporary handle for GetSelection Style. */
  89.  
  90.     thisHndl = GetCtlHandleFromID(FrontWindow(), MainWindowID);
  91.         /* Get the handle to the TE control for the top window. */
  92.     
  93.     TEGetSelectionStyle(&thisStyle, tempHndl, thisHndl);
  94.         /* Get the current font of the selection. */
  95.  
  96.     thisStyle.styleFontID.fidLong = ChooseFont(thisStyle.styleFontID.fidLong, 0);
  97.         /* Use it as the default for ChooseFont. */
  98.  
  99.     TEStyleChange(teReplaceFont+teReplaceSize+teReplaceAttributes,
  100.         &thisStyle, thisHndl);          /* Set font to user's choice. */
  101.  
  102.     DisposeHandle(tempHndl);            /* Get rid of the handle. */
  103. }
  104.  
  105.  
  106.  
  107. /*********************************************************************
  108. * doSetFont
  109. *
  110. * Change the family number for the selected text for the top window.
  111. *
  112. *********************************************************************/
  113. void            doSetFont(theFam)
  114. unsigned int    theFam;
  115. {
  116.     CtlRecHndl  thisHndl;
  117.     TEStyle     thisStyle;
  118.  
  119.     thisHndl = GetCtlHandleFromID(FrontWindow(), MainWindowID);
  120.         /* Get the handle to the TE control for the top window. */
  121.  
  122.     thisStyle.styleFontID.fidRec.famNum = theFam;
  123.  
  124.     TEStyleChange(teReplaceFont, &thisStyle, thisHndl);
  125.         /* Set font to user's choice. */
  126. }
  127.  
  128.  
  129.  
  130. /*********************************************************************
  131. * doSetSize
  132. *
  133. * Change the font size for the selected text for the top window.
  134. *
  135. *********************************************************************/
  136. void            doSetSize(theSize)
  137. unsigned int    theSize;
  138. {
  139.     CtlRecHndl  thisHndl;
  140.     TEStyle     thisStyle;
  141.  
  142.     thisHndl = GetCtlHandleFromID(FrontWindow(), MainWindowID);
  143.         /* Get the handle to the TE control for the top window. */
  144.  
  145.     thisStyle.styleFontID.fidRec.fontSize = theSize;
  146.  
  147.     TEStyleChange(teReplaceSize, &thisStyle, thisHndl);
  148. }
  149.  
  150.  
  151.  
  152. /*********************************************************************
  153. * doSetStyle
  154. *
  155. *********************************************************************/
  156. void            doSetStyle(theStyle)
  157. unsigned int    theStyle;
  158. {
  159.     CtlRecHndl  thisHndl;
  160.     TEStyle     thisStyle;
  161.  
  162.     thisHndl = GetCtlHandleFromID(FrontWindow(), MainWindowID);
  163.         /* Get the handle to the TE control for the top window. */
  164.  
  165.     thisStyle.styleFontID.fidRec.fontStyle = theStyle;
  166.         
  167.     if (!theStyle) {
  168.         TEStyleChange(teReplaceAttributes, &thisStyle, thisHndl);
  169.     }
  170.     else {
  171.         TEStyleChange(teSwitchAttributes, &thisStyle, thisHndl);
  172.     }
  173. }
  174.  
  175.  
  176.  
  177. /*********************************************************************
  178. * doMenu
  179. *
  180. * Function to handle all menu selections.  Examines the Event.TaskData
  181. * menu item ID word from TaskMaster (from Event Manager) and calls the
  182. * appropriate routine.  While the routine is running the menu title is
  183. * still highlighted.  After the routine returns, we unhilight the
  184. * menu title.
  185. *
  186. *********************************************************************/
  187. void    doMenu()
  188. {
  189.     unsigned int    menuNum, itemNum;
  190.  
  191.     menuNum = HiWord (event.wmTaskData);
  192.     itemNum = LoWord (event.wmTaskData);
  193.     
  194.     switch(itemNum) {
  195.         case AboutItem:
  196.             doAboutItem();
  197.             break;
  198.         case CloseItem:
  199.             doCloseTop();
  200.             break;
  201.         case QuitItem:
  202.             doQuitItem();
  203.             break;
  204.         case UndoItem:              /* Handled by taskmaster */
  205.         case CutItem:               /* Handled by taskmaster */
  206.         case CopyItem:              /* Handled by taskmaster */
  207.         case PasteItem:             /* Handled by taskmaster */
  208.         case ClearItem:             /* Handled by taskmaster */
  209.             break;
  210.         case SelectAllItem:
  211.             doSelectAll();
  212.             break;
  213.         case NewItem:
  214.             doNewWindow();
  215.             break;
  216.         case OpenItem:
  217.             doOpenWindow();
  218.             break;
  219.         case SaveItem:
  220.             doSave();
  221.             break;
  222.         case SaveAsItem:
  223.             doSaveAs();
  224.             break;
  225.         case PageSetupItem:
  226.             break;                  /* Not implemented yet. */
  227.         case PrintItem:
  228.             break;                  /* Not implemented yet. */
  229.         case PlainItem:
  230.             doSetStyle(0);
  231.             break;
  232.         case BoldItem:
  233.             doSetStyle(boldMask);
  234.             break;
  235.         case ItalicItem:
  236.             doSetStyle(italicMask);
  237.             break;
  238.         case UnderlineItem:
  239.             doSetStyle(underlineMask);
  240.             break;
  241.         case ShadowItem:
  242.             doSetStyle(shadowMask);
  243.             break;
  244.         case OutlineItem:
  245.             doSetStyle(outlineMask);
  246.             break;
  247.         case Size8Item:
  248.             doSetSize(8);
  249.             break;
  250.         case Size10Item:
  251.             doSetSize(10);
  252.             break;
  253.         case Size12Item:
  254.             doSetSize(12);
  255.             break;
  256.         case Size16Item:
  257.             doSetSize(16);
  258.             break;
  259.         case Size20Item:
  260.             doSetSize(20);
  261.             break;
  262.         case Size24Item:
  263.             doSetSize(24);
  264.             break;
  265.         case ChooseFontItem:
  266.             doChooseFont();
  267.             break;
  268.         default:
  269.             if (itemNum >= FirstFontItem) doSetFont(ItemID2FamNum(itemNum));
  270.             break;
  271.     }
  272.  
  273.     HiliteMenu(0, menuNum);     /* Unhighlight the menu title. */
  274. }
  275.  
  276.  
  277.  
  278. /*********************************************************************
  279. * setupMenus
  280. *
  281. * Function to install our menu titles and their items in the system menu
  282. * bar and to redraw it so we can see them.
  283. *
  284. *********************************************************************/
  285. void    setupMenus()
  286. {
  287.     SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
  288.     SetMenuBar(NULL);
  289.     
  290.     FixAppleMenu(AppleMenuID);              /* Add DAs to apple menu. */
  291.  
  292.     FixFontMenu(FontMenuID, FirstFontItem, 0);
  293.  
  294.     FixMenuBar();                           /* Set sizes of menus. */
  295.     
  296.     /* Rather than drawing menu bar here, I rely on FixFrontW to do it first
  297.     time through event loop. */
  298. }
  299.